﻿using System;
using System.Runtime.InteropServices;
using System.Threading;

namespace HalconDotNet
{
	// Token: 0x02000098 RID: 152
	internal class HTupleInt32 : HTupleImplementation
	{
		// Token: 0x06001F67 RID: 8039 RVA: 0x000B9A7A File Offset: 0x000B7C7A
		protected override Array CreateArray(int size)
		{
			return new int[size];
		}

		// Token: 0x06001F68 RID: 8040 RVA: 0x000B9A82 File Offset: 0x000B7C82
		protected override void NotifyArrayUpdate()
		{
			this.i = (int[])this.data;
		}

		// Token: 0x06001F69 RID: 8041 RVA: 0x000B9A95 File Offset: 0x000B7C95
		internal override void PinTuple()
		{
			Monitor.Enter(this);
			if (this.pinCount == 0)
			{
				this.pinHandle = GCHandle.Alloc(this.i, GCHandleType.Pinned);
			}
			this.pinCount++;
			Monitor.Exit(this);
		}

		// Token: 0x06001F6A RID: 8042 RVA: 0x000B9ACB File Offset: 0x000B7CCB
		public HTupleInt32(int i)
		{
			base.SetArray(new int[]
			{
				i
			}, false);
		}

		// Token: 0x06001F6B RID: 8043 RVA: 0x000B9AE4 File Offset: 0x000B7CE4
		public HTupleInt32(int[] i, bool copy)
		{
			base.SetArray(i, copy);
		}

		// Token: 0x06001F6C RID: 8044 RVA: 0x000B9AF4 File Offset: 0x000B7CF4
		public override HTupleElements GetElement(int index, HTuple parent)
		{
			return new HTupleElements(parent, this, index);
		}

		// Token: 0x06001F6D RID: 8045 RVA: 0x000B9AFE File Offset: 0x000B7CFE
		public override HTupleElements GetElements(int[] indices, HTuple parent)
		{
			if (indices == null || indices.Length == 0)
			{
				return new HTupleElements();
			}
			return new HTupleElements(parent, this, indices);
		}

		// Token: 0x06001F6E RID: 8046 RVA: 0x000B9B15 File Offset: 0x000B7D15
		public override void SetElements(int[] indices, HTupleElements elements)
		{
			new HTupleElementsInt32(this, indices).setI(elements.IArr);
		}

		// Token: 0x17000094 RID: 148
		// (get) Token: 0x06001F6F RID: 8047 RVA: 0x000B9B29 File Offset: 0x000B7D29
		// (set) Token: 0x06001F70 RID: 8048 RVA: 0x000B9B31 File Offset: 0x000B7D31
		public override int[] IArr
		{
			get
			{
				return this.i;
			}
			set
			{
				base.SetArray(value, false);
			}
		}

		// Token: 0x17000095 RID: 149
		// (get) Token: 0x06001F71 RID: 8049 RVA: 0x000B8475 File Offset: 0x000B6675
		public override HTupleType Type
		{
			get
			{
				return HTupleType.INTEGER;
			}
		}

		// Token: 0x06001F72 RID: 8050 RVA: 0x000B9B3B File Offset: 0x000B7D3B
		public override int[] ToIArr()
		{
			return (int[])base.ToArray(this.typeI);
		}

		// Token: 0x06001F73 RID: 8051 RVA: 0x000B9B4E File Offset: 0x000B7D4E
		public override long[] ToLArr()
		{
			return (long[])base.ToArray(this.typeL);
		}

		// Token: 0x06001F74 RID: 8052 RVA: 0x000B9B61 File Offset: 0x000B7D61
		public override double[] ToDArr()
		{
			return (double[])base.ToArray(this.typeD);
		}

		// Token: 0x06001F75 RID: 8053 RVA: 0x000B9B74 File Offset: 0x000B7D74
		public override float[] ToFArr()
		{
			return (float[])base.ToArray(this.typeF);
		}

		// Token: 0x06001F76 RID: 8054 RVA: 0x000B9B88 File Offset: 0x000B7D88
		public override IntPtr[] ToIPArr()
		{
			if (HalconAPI.isPlatform64)
			{
				base.ToIPArr();
			}
			IntPtr[] array = new IntPtr[this.iLength];
			for (int i = 0; i < this.iLength; i++)
			{
				array[i] = new IntPtr(this.i[i]);
			}
			return array;
		}

		// Token: 0x06001F77 RID: 8055 RVA: 0x000B9BD1 File Offset: 0x000B7DD1
		public override int CopyToIArr(int[] dst, int offset)
		{
			Array.Copy(this.data, 0, dst, offset, this.iLength);
			return this.iLength;
		}

		// Token: 0x06001F78 RID: 8056 RVA: 0x000B9BF0 File Offset: 0x000B7DF0
		public override int CopyToOArr(object[] dst, int offset)
		{
			for (int i = 0; i < this.iLength; i++)
			{
				dst[i + offset] = this.i[i];
			}
			return this.iLength;
		}

		// Token: 0x06001F79 RID: 8057 RVA: 0x000B9C26 File Offset: 0x000B7E26
		public override int CopyFrom(HTupleImplementation impl, int offset)
		{
			return impl.CopyToIArr(this.i, offset);
		}

		// Token: 0x06001F7A RID: 8058 RVA: 0x000B9C38 File Offset: 0x000B7E38
		public override void Store(IntPtr proc, int parIndex)
		{
			IntPtr tuple;
			HalconAPI.HCkP(proc, HalconAPI.GetInputTuple(proc, parIndex, out tuple));
			this.StoreData(proc, tuple);
		}

		// Token: 0x06001F7B RID: 8059 RVA: 0x000B9C5C File Offset: 0x000B7E5C
		protected override void StoreData(IntPtr proc, IntPtr tuple)
		{
			this.PinTuple();
			if (HalconAPI.isPlatform64)
			{
				HalconAPI.HCkP(proc, HalconAPI.CreateElementsOfType(tuple, base.Length, HTupleType.INTEGER));
				for (int i = 0; i < base.Length; i++)
				{
					HalconAPI.SetI(tuple, i, this.i[i]);
				}
				return;
			}
			HalconAPI.SetIArrPtr(tuple, this.i, this.iLength);
		}

		// Token: 0x06001F7C RID: 8060 RVA: 0x000B9CC0 File Offset: 0x000B7EC0
		public static int Load(IntPtr tuple, out HTupleInt32 data)
		{
			int num;
			HalconAPI.GetTupleLength(tuple, out num);
			int[] intArray = new int[num];
			int iarr = HalconAPI.GetIArr(tuple, intArray);
			data = new HTupleInt32(intArray, false);
			return iarr;
		}

		// Token: 0x04001186 RID: 4486
		protected int[] i;
	}
}
